package quick.frame.service;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;


import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import quick.frame.core.delegates.QuickDelegate;

public class TestRxJAVA2 extends QuickDelegate {
    @Override
    public Object setLayout() {
        return R.layout.delegate_rxjava2;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
       /* Button button = new Button(getContext());
        button.setText("rxJava");
        rootView.setId(button.getId()); */
        Observable.create(new ObservableOnSubscribe<String>() {


            @Override
            public void subscribe(ObservableEmitter<String> emitter) throws Exception {
                if(emitter.isDisposed()){
                    System.out.println("currentThread: "+Thread.currentThread());
                    emitter.onNext("test");
                    emitter.onComplete();
                }
            }
        }).subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
